﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using ExtBusiness.User;
using ExtBusiness.Interface;
using System.Data.Common;
using System.Data.OracleClient;


public partial class WebPubManager_UserPassSet : System.Web.UI.Page
{
    public string strId = "";
    InterfaceOperation infaceOperation = new InterfaceOperation();
    string strXml = string.Empty;
    string strExMsg = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["id"] != null)
        {
            strId = Request.Params["id"];
        }
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (hfFlag.Value == "1")
        {
            return;
        }
        if (rblUserPwdType.SelectedValue == "0")//与UserID相同
        {
            //先更新密码
            UserManager.UpdatePassword(strId);            
        }
        if (rblUserPwdType.SelectedValue == "1")//随机密码
        {
            UserManager.UpdatePassSet(strId);
        }
        if (rblUserPwdType.SelectedValue == "2")//指定密码
        {
            string strUserPwd = txtUserRePwd.Text.Trim().ToString();
            UserManager.UpdatePassSet(strId, strUserPwd);
        }
        UpdateUserInfo();

        //在wondow.open方式打开时,刷新父页面并关闭 addby zhongjian 20090927
        //this.Response.Write("<script>window.opener.location.reload();</script>");
        //Page.RegisterStartupScript("function", "<script>windowClose();</script>");

        //在showModalDialog打开页面时,刷新父页面并关闭 addby zhongjian 20091019
        this.Response.Write("<script>window.returnValue = 'True';</script>");//设置返回值为True,在父页面刷新
        this.Response.Write("<script>window.close();</script>");
    }
    protected void rblUserPwdType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rblUserPwdType.SelectedValue == "0" || rblUserPwdType.SelectedValue == "1")
        {
            this.trUserPwd.Visible = false;
            this.trUserRePwd.Visible = false;
        }
        if (rblUserPwdType.SelectedValue == "2")
        {
            this.trUserPwd.Visible = true;
            this.trUserRePwd.Visible = true;
        }
    }
    /// <summary>
    /// 更新用户信息(地信中心接口)
    /// </summary>
    /// <!--update by zhongjian 20100120-->
    protected void UpdateUserInfo()
    {
        try
        {
            //获取用户信息,并生成XML内容.
            strXml = infaceOperation.GetUserInfoXml(strId, "update");
            strExMsg = "";
            if (!string.IsNullOrEmpty(strXml))
            {
                //DxInterface.IdsService idsTemp = new DxInterface.IdsService();
                string strCheckCode = Common.Encode.Md5(DateTime.Now.ToShortDateString());
                //更新用户信息 

                strExMsg = "重置密码接口更新成功!";

            }
        }
        catch (Exception ex)
        {
            strExMsg = ex.ToString();
        }
        finally 
        {
            //当为本系统用户时,无需更新接口,不再写入日志.
            if(!string.IsNullOrEmpty(strExMsg))
                infaceOperation.UpdateExceptionAndXml(strXml, strExMsg, 10);
        }
    }

}
